package com.prs.crm.domain.project;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.prs.crm.domain.SimpleFlowEntity;
import com.prs.crm.domain.hr.Person;

/**
 * 任务传阅
 * @author prs.chenzhi
 *
 */
@Entity
@Table(name="prj_taskperusal")
public class TaskPerusal extends SimpleFlowEntity{

	private static final long serialVersionUID = 1L;
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	@ManyToMany(fetch = FetchType.LAZY)
	private Set<Person> recivers;
	
	@ManyToOne(cascade = {CascadeType.MERGE,CascadeType.PERSIST})
	@OrderBy
	private Task task;
	
	/**
	 * 原因
	 */
	@Lob
	private String reason;
	
	private Integer status;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setRecivers(Set<Person> recivers) {
		this.recivers = recivers;
	}

	public Set<Person> getRecivers() {
		return recivers;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public Task getTask() {
		return task;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getReason() {
		return reason;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getStatus() {
		return status;
	}
	
	public void addAllReciver(Collection<Person> persons)
	{
		if (recivers==null)
			recivers = new HashSet<Person>();
		recivers.addAll(persons);
	}

	public void addReciver(Person person)
	{
		if (recivers==null)
			recivers = new HashSet<Person>();
		recivers.add(person);
	}
}
